package com.actionpals.geom
{
	/**
	 * The RGB class offers another representation of color.
	 * 
	 * @author Mark Walters
	 */	
	public class RGB
	{
		private var _red:uint;
		private var _green:uint;
		private var _blue:uint;
		
		/**
		 * Constructor.
		 * 
		 * @param red
		 * @param green
		 * @param blue
		 */		
		public function RGB( red:uint = 0, green:uint = 0, blue:uint = 0 )
		{
			this.red = red;
			this.green = green;
			this.blue = blue;
		}
		
		/**
		 * The red color value, as a number between 0 and 255.
		 */	
		public function get red():uint
		{
			return _red;
		}
		
		/**
		 * @private
		 */	
		public function set red( value:uint ):void
		{
			_red = Math.min( value, 255 );
		}
		
		/**
		 * The green color value, as a number between 0 and 255.
		 */	
		public function get green():uint
		{
			return _green;
		}
		
		/**
		 * @private
		 */	
		public function set green( value:uint ):void
		{
			_green = Math.min( value, 255 );
		}
		
		/**
		 * The blue color value, as a number between 0 and 255.
		 */	
		public function get blue():uint
		{
			return _blue;
		}
		
		/**
		 * @private
		 */	
		public function set blue( value:uint ):void
		{
			_blue = Math.min( value, 255 );
		}
		
		/**
		 * The hexadecimal color value for an RGB object.
		 */	
		public function get color():uint
		{
			return ( red << 16 | green << 8 | blue );
		}
		
		/**
		 * @private
		 */	
		public function set color( value:uint ):void
		{
			red = ( value >> 16 ) & 0xFF;
			green = ( value >> 8 ) & 0xFF;
			blue = value & 0xFF;
		}
		
		/**
		 * The string version of an RGB object.
		 */	
		public function toString():String
		{
			return "[RGB red=" + red + " green=" + green + " blue=" + blue + "]";
		}
		
	}
}